﻿using CPPEI.ETL.Domain.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.ETL.Domain.Services
{
    public class DtTableQueryService
    {
        /// <summary>
        /// 获取未映射的数据表
        /// </summary>
        /// <returns></returns>
        public PagedList<Entities.EDtTable> GetUnmappedTables(string filter, int start, int limit)
        {
            using (EtlDbContext dbContext = new EtlDbContext())
            {
                List<Entities.EDtTable> list = dbContext.Database.SqlQuery<Entities.EDtTable>("exec [ETL_SP_GetUnmappedDtTables] @Filter={0},@Start={1},@Limit={2}",
                    filter, start, limit).ToList();
                int total = dbContext.Database.SqlQuery<int>("exec [ETL_SP_GetUnmappedDtTableTotal] @Filter={0}", filter).SingleOrDefault();
                return new PagedList<Entities.EDtTable>(true, ErrorCode.COM_NoError, "", start, limit, total, list);
            }
        }

        /// <summary>
        /// 获取已经映射的数据表
        /// </summary>
        /// <returns></returns>
        public PagedList<Entities.EDtTable> GetMappedTables(string filter, int start, int limit)
        {
            using (EtlDbContext dbContext = new EtlDbContext())
            {
                List<Entities.EDtTable> list = dbContext.Database.SqlQuery<Entities.EDtTable>("exec [ETL_SP_GetMappedDtTables] @Filter={0},@Start={1},@Limit={2}",
                    filter, start, limit).ToList();

                int total = dbContext.Database.SqlQuery<int>("exec [ETL_SP_GetMappedDtTableTotal] @Filter={0}", filter).SingleOrDefault();
                return new PagedList<Entities.EDtTable>(true, ErrorCode.COM_NoError, "", start, limit, total, list);
            }
        }
    }
}
